// 获取要操作的元素
let lis=document.querySelectorAll('li'),
    rbs=document.querySelectorAll('.rb'),
    line=document.querySelector('.line');

// 循环绑定li的点击事件，并设置选中态样式
lis.forEach((item,index)=>{
    item.addEventListener('click',function(){
        lis.forEach((item1)=>{
            item1.classList.remove('active');
        })
        rbs.forEach((item2)=>{
            item2.classList.remove('active');
        })
        lis[index].classList.add('active');
        rbs[index].classList.add('active');
        line.className='line line'+(index+1); //index是从0开始，所以这里要+1
    })
})


// ================================================

const second = 60;
let delay = second;
let timer = null;
let btn = null;

function fn(){
    if(delay != 0){
        btn.innerText = delay+'s';
        btn.style.backgroundColor = "#999"
        delay--;
    }else {
        clearInterval(timer);
        btn.innerText = "重新获取";
        btn.style.backgroundColor = "orange";
        delay = second;
        btn.disabled = false
    }
    return fn
}

function emailCode(){
    var telephone;
    var form=document.getElementById("email_form");
    var formData=new FormData(form);
    telephone = formData.get("telephone");
    btn = document.querySelector("#getCode");
    // btn.onclick=function (){
    btn.disabled = true;
    timer = setInterval(fn(),1000);
    // }
    var url = "getCodeNum/"+telephone;
    window.location.href=url;
}


function modifyPhoneCode(){
    var telephone;
    var form=document.getElementById("phone_form");
    var formData=new FormData(form);
    telephone = formData.get("telephone");

    btn = document.querySelector("#getCode_phone");
    // btn.onclick=function (){
    btn.disabled = true;
    timer = setInterval(fn(),1000);
    // }

    var url = "getCodeNum/"+telephone;
    window.location.href=url;
}


// ==========================验证码刷新=========================================
window.onload=function (){

    let phone = document.getElementById("phone");
    phone.onclick=function (){
        this.src = "http://172.24.165.54:8080/defaultKaptchaPhone?_="+Date.now();
        console.log('phone'+Math.random());
    }


    let email = document.getElementById("email");
    email.onclick=function (){
        this.src = "http://172.24.165.54:8080/defaultKaptchaEmail?_="+Date.now();
        console.log('email'+Math.random());
    }
}





